//
//  DetailCell.m
//  phmall
//
//  Created by admin on 2017/11/14.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "DetailCell.h"

@implementation DetailCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
+ (instancetype)theShareCellWithTableView:(UITableView *)tableView{
    
    static NSString *ID = @"SetCell";
    DetailCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[DetailCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;;
    }
    return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.type=[[UILabel alloc]init];
        self.type.text=@"收入";
        self.type.font=[UIFont systemFontOfSize:13];
        [self.contentView addSubview:self.type];
        
        self.time=[[UILabel alloc]init];
        self.time.text=@"2017-01-08 9:25";
        self.time.font=[UIFont systemFontOfSize:13];
        self.time.textColor=[UIColor colorWithHexString:@"#adadad"];
        [self.contentView addSubview:self.time];
        
        self.money=[[UILabel alloc]init];
        self.money.text=@"₱8888.80";
        self.money.font=[UIFont systemFontOfSize:20];
//        self.money.textColor=[UIColor colorWithHexString:@"#454545"];
        [self.contentView addSubview:self.money];

        self.line=[[UIView alloc]init];
        self.line.backgroundColor=[UIColor groupTableViewBackgroundColor];
        [self.contentView addSubview:self.line];
        
        
    }
    return self;
}
-(void)layoutSubviews{
    [super layoutSubviews];
    CGSize superSize = self.contentView.frame.size;
    
    if (CGSizeEqualToSize(superSize, CGSizeZero)) {
        return;
    }
    [self.type mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(10);
        make.top.offset(6);
    }];
    
    [self.time mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(10);
        make.bottom.offset(-6);
    }];
    
    [self.money mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.right.offset(-10);
    }];

    
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(0);
        make.right.offset(0);
        make.height.offset(1);
        make.bottom.offset(0);
    }];
}
-(void)setModel:(FinancialModel *)model{
    _model=model;
    self.type.text=model.type;
    self.time.text=[PublicClass timeWithTimeIntervalString:model.approval_date];
    
    if (model.point_add!=nil) {
          self.money.text=[NSString stringWithFormat:@"%.2f",[model.point_add doubleValue]];
    }else{
        if ([model.money_add doubleValue]>=0) {
            self.money.text=[NSString stringWithFormat:@"₱%.2f",[model.money_add doubleValue]];
        }else{
            self.money.text=[NSString stringWithFormat:@"-₱%.2f",-[model.money_add doubleValue]];
        }
    }
    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
